package com.example.ecommerce.controller;

import com.example.ecommerce.dto.ProductSpecDTO;
import com.example.ecommerce.service.ProductSpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/productSpecs")
public class ProductSpecController {
    @Autowired
    private ProductSpecService specService;

    @GetMapping("/product/{productId}")
    public ResponseEntity<List<ProductSpecDTO>> getProductSpecs(@PathVariable Long productId) {
        return ResponseEntity.ok(specService.getSpecsByProductId(productId));
    }

    @PostMapping
    public ResponseEntity<ProductSpecDTO> createSpec(@RequestBody ProductSpecDTO specDTO) {
        return ResponseEntity.ok(specService.createSpec(specDTO));
    }

    @PutMapping("/{id}")
    public ResponseEntity<ProductSpecDTO> updateSpec(
            @PathVariable Long id,
            @RequestBody ProductSpecDTO specDTO) {
        return ResponseEntity.ok(specService.updateSpec(id, specDTO));
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteSpec(@PathVariable Long id) {
        specService.deleteSpec(id);
        return ResponseEntity.ok().build();
    }
} 